import { getRequest, postRequestLogin, postRequest, postFormRequest } from '@/utils/http'
import type { Result } from '@/types/result'

/* interface CaptchaParams {
  phone: string
  [key: string]: unknown // 添加索引签名
  // 其他字段...
}*/
export interface UserLoginDTO {
  phone: string
  password?: string
  captcha?: string
  [key: string]: unknown // 添加索引签名
}

// 发送验证码
export const sendCaptcha = (phone: string): Promise<Result> => {
  return postFormRequest('/common/sendCaptcha', { phone })
}
//  用户登录
export const userLogin = (
  data: UserLoginDTO,
  isPasswordLogin: boolean,
): Promise<Result<{ username: string; avatar: string; token: string }>> => {
  return postRequestLogin('/user/login', data, {
    params: { isPasswordLogin },
  })
}
//用户注册
export const userRegister = (params: UserLoginDTO): Promise<Result> => {
  return postRequest('/user/register', params)
}
//获取菜单
export const getMenu = (): Promise<Result<[]>> => {
  return getRequest('/common/menu')
}
/* //  用户登录
export const userLogin = (params: UserLoginDTO, isPasswordLogin: boolean) => {
  return post2('/user/login', params, {
    params: { isPasswordLogin }, // 这里 now works!
  })
} */
